# -*- coding: utf-8 -*-
# @Time    : 2021/9/17 15:21
# @Author  : huangwei
# @File    : method.py
# @Software: PyCharm
import os
import cv2
import base64


def create_dir( dir_path ):
    """创建文件夹"""
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)
        print("create path:", dir_path)
    else:
        print("%s is exists" % dir_path)


def getByte( path ):
    with open(path, 'rb') as f:
        img_byte = base64.b64encode(f.read())  # 二进制读取后变base64编码
    img2str = str(img_byte, encoding='utf-8')  # 转为str
    return img2str


def draw_box( img, box ):
    x1, y1, x2, y2, x3, y3, x4, y4 = box
    p1 = (int(x1), int(y1))
    p2 = (int(x2), int(y2))
    p3 = (int(x3), int(y3))
    p4 = (int(x4), int(y4))

    cv2.line(img, p1, p2, (0, 255, 0), 1)
    cv2.line(img, p2, p3, (0, 255, 0), 1)
    cv2.line(img, p3, p4, (0, 255, 0), 1)
    cv2.line(img, p4, p1, (0, 255, 0), 1)

    return img
